package com.njlime.member.service.app;

import com.njlime.core.helper.PageBean;
import com.njlime.member.entiies.MemberCollection;
import com.njlime.member.repository.app.AppMemberCollectionDao;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Map;

/**
 * Created by Dean on 2017/10/9.
 */
@Service
public class AppMemberCollectionService {
    @Resource
    private AppMemberCollectionDao appMemberCollectionDao;

    /**
     * 用户添加收藏
     *
     * @param memberCollection
     */
    @Transactional(readOnly = false)
    public void save(MemberCollection memberCollection) {
        appMemberCollectionDao.save(memberCollection);
    }

    /**
     * 判断当前用户是否收藏该信息
     */
    public boolean isCollected(Integer uid, Integer business_id, Integer collection_type) {
        Map<String, Object> bean = appMemberCollectionDao.get(uid, business_id, collection_type);
        return bean == null ? false : true;
    }

    /**
     * 判断当前用户是否收藏该信息
     */
    public Map<String, Object> get(Integer uid, Integer business_id, Integer collection_type) {
        return appMemberCollectionDao.get(uid, business_id, collection_type);
    }

    /**
     * 获取收藏数量
     * @param business_id
     * @param collection_type
     * @return
     */
    public int count(Integer business_id, Integer collection_type){
        return appMemberCollectionDao.count(business_id,collection_type);
    }

    /**
     * 收藏列表分页
     *
     * @param pageBean
     * @param memberCollection
     * @return
     */
    public PageBean collectionList(PageBean pageBean, MemberCollection memberCollection) {
        return appMemberCollectionDao.getMemberCollectionList(pageBean, memberCollection);
    }

    /**
     * 删除收藏
     *
     * @param id
     */
    public void del(Integer id) {
        appMemberCollectionDao.delete(id);
    }
}
